﻿/*+===================================================================
File:      Fire.cpp

Summary:   Định nghĩa các phương thức của CFire.
===================================================================+*/

#include "Fire.h"

#define LIMIT_DISTANCE 200.0f
#define VX 100.0f

CFire::CFire(D3DXVECTOR2 pos, int id, int typeID, int directionX) : CMoveableObject(pos, id, typeID)
{
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_FIRE);
	m_pSprite = m_pResourceManager->GetSprite(ID_SPRITE_FIRE);

	if (directionX > 0)
	{
		m_limitX1 = m_pos.x - LIMIT_DISTANCE;
		m_limitX2 = m_pos.x;
		m_v.x = -VX;
	}
	else
	{
		m_limitX1 = m_pos.x;
		m_limitX2 = m_pos.x + LIMIT_DISTANCE;
		m_v.x = VX;
	}

	m_box.width = 42;
	m_box.height = 32;
}


CFire::~CFire()
{

}

void CFire::Update(float timeFrame)
{
	if (!m_bIsLive)
		return;

	m_pos += m_v* timeFrame;

	if (m_pos.x < m_limitX1)
	{
		m_pos.x = m_limitX1;
		m_v.x = VX;
	}
	else if (m_pos.x > m_limitX2)
	{
		m_pos.x = m_limitX2;
		m_v.x = -VX;
	}

	m_pSprite->Update(timeFrame);
	UpdateBox(timeFrame);
}